home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-14 | 2.1 KB | 77 lines | [TEXT/MPS ] |
- // Sound.cp
-
- /* _________________________________________________________________________________________________________ //
- Copyright © 1992-93 Apple Computer, Inc. All rights reserved.
- Macintosh Developer Technical Support.C++ Macintosh Toolbox Framework.
- Programmer: Kent Sandvik
- Date: 12/21/92
- Revision comments are at the end of this file.
- ---
- TSound is a simple object that plays sounds
- TSound.cp contains the TSound member functions.
- _________________________________________________________________________________________________________ */
-
- #ifndef _SOUND_
- #include "SoundClass.h"
- #endif
-
-
- // CONSTRUCTORS AND DESTRUCTORS
- #pragma segment Sound
- TSound::TSound(char* name)
- // Construct the TSound class using the string name for the sound resource.
- {
- strcpy(fSound, name);
- c2p(fSound); // convert it to a Pascal string
-
- fSoundHandle = ::GetNamedResource(kSoundType, (ConstStr255Param)fSound);// get the resource
- ASSERT(fSoundHandle != NULL, "\pDidn't find the Sound Resource");
- if (fSoundHandle != NULL)
- ::DetachResource(fSoundHandle); // detach it so we could have multiple copies in memory
- }
-
-
- TSound::TSound(short resID)
- // Construct the TSound class using a resource ID.
- {
- fSoundID = resID;
- fSoundHandle = ::GetResource(kSoundType, fSoundID);
- ASSERT(fSoundHandle != NULL, "\pDidn't find the Sound Resource");
- if (fSoundHandle != NULL)
- ::DetachResource(fSoundHandle); // detach it so we could have multiple copies in memory
- }
-
-
- #pragma segment Sound
- TSound::~TSound()
- // Destruct the sound handle.
- {
- if (fSoundHandle != NULL) // we have a valid snd handle
- {
- ::DisposeHandle(fSoundHandle);
- }
- }
-
-
- // MAIN INTERFACE
- #pragma segment Sound
- void TSound::Play()
- // Play the selected sound.
- {
- if (fSoundHandle != NULL) // we have a valid snd handle
- {
- fError = ::SndPlay(NULL, fSoundHandle, false);// play synchronously
- VASSERT(fError == noErr, ("Problems with SndPlay = %d\n", fError));
- }
- }
-
-
- // _________________________________________________________________________________________________________ //
-
-
- /* Change History (most recent last):
- No Init. Date Comment
- 1 khs 12/21/92 New file
- 2 khs 1/14/93 Cleanup
- */
-